package result

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
	Success bool        `json:"success"`
}

// 成功响应
func Success(c *gin.Context, data interface{}) {
	c.JSON(http.StatusOK, Response{
		Code:    200,
		Message: "成功",
		Data:    data,
		Success: true,
	})
}

// 失败响应
func Error(c *gin.Context, code int, message string) {
	c.JSON(http.StatusOK, Response{
		Code:    code,
		Message: message,
		Data:    nil,
		Success: false,
	})
}

// 带状态码的失败响应
func ErrorWithStatus(c *gin.Context, statusCode, code int, message string) {
	c.JSON(statusCode, Response{
		Code:    code,
		Message: message,
		Data:    nil,
		Success: false,
	})
}
